' Written by Craig'n'Dave
Module Module1
    ' Stack using an array
    Public Class Stack
        Private max As Integer = 10
        Private items(max) As String

        Private stack_pointer = 1

        Function push(item As String)
            ' Check stack overflow
            If stack_pointer < max Then
                stack_pointer = stack_pointer + 1
                ' Push the item
                items(stack_pointer) = item
                Return True
            Else
                Return False
            End If
        End Function

        Function pop()
            ' Check stack underflow
            If stack_pointer <> -1 Then
                ' Pop the item
                Dim item As String = items(stack_pointer)
                stack_pointer = stack_pointer - 1
                Return item
            Else
                Return Nothing
            End If
        End Function

        Function peek()
            ' Check stack underflow
            If stack_pointer <> -1 Then
                ' Peek the item
                Return items(stack_pointer)
            Else
                Return Nothing
            End If
        End Function
    End Class

    ' Main program starts here
    Sub Main()
        Dim items() As String = {"Florida", "Georgia", "Delaware", "Alabama", "California"}
        Dim s As New Stack
        ' Add items to the stack
        For index = 0 To items.Length - 1
            s.push(items(index))
        Next
        'Remove items from the stack
        Console.WriteLine(s.pop)
        ' Output the next item in the stack
        Console.WriteLine(s.peek)
    End Sub
End Module